package com.woniuxy.creditsystem.common.mapper;

import com.woniuxy.creditsystem.common.bean.MenuInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 查询所有的菜单
 * @author hejie
 */
@Mapper
public interface MenuMapper {

    /**
     * 查询所有的菜单
     * @return
     */
    @ResultType(MenuInfo.class)
    @Select("select id,menu_name as menuName,menu_level as menuLevel from menu_info")
    public List<MenuInfo> findAll();

    /**
     * 根据 roleInfo.id查询  该角色能看到的所有菜单
     * @param id
     * @return
     */
    @ResultType(MenuInfo.class)
    @Select("select m.id, menu_name menuName, menu_desc menuDesc from menu_info m,role_menu_info rm" +
            " where rm.fk_role_id=#{roleId} and rm.fk_menu_id=m.id")
    public List<MenuInfo> findMenuByRoleId(@Param("roleId") int roleId);

}
